﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CFSystem.JXC.BasisInfo
{
    internal static class Common
    {
        internal static string CheckIsEmpty(string lblField, object value)
        {
            string result = string.Empty;

            if (!(value is DBNull) && value != null)
            {
                result = value.ToString().Trim();
            }

            if (result == string.Empty)
            {
                throw new Exception(lblField.Trim().Split('"')[0] + "不能为空!");
            }

            return result;
        }

        internal static int CheckNumber(string lblField, object obj)
        {
            int result;
            if (obj != null && Int32.TryParse(obj.ToString().Trim(), out result))
            {
                return result;
            }
            else if (obj.ToString().Trim() == string.Empty)
            {
                return 0;
            }
            else
            {
                throw new Exception(lblField.Trim().Split('"')[0] + "必须为数字!");
            }
        }

        internal static string GetStringValue(object obj)
        {
            if (obj == null)
            {
                return string.Empty;
            }
            else
            {
                return obj.ToString().Trim();
            }
        }

        internal static int GetIntegerValue(object obj)
        {
            int result;
            if (obj == null)
            {
                return -1;
            }
            else if (Int32.TryParse(obj.ToString().Trim(), out result))
            {
                return result;
            }
            else
            {
                return -1;
            }
        }
    }
}
